package taper.controller;

import util.UnitConversion;

public class MewtocolCommand {

	public static final String error = "!";
	public static final String noError = "$";
	public static final String monitorResult = "MG";
	private static final String unitCode = "S";   //specify S to read single bit of data
	private static final String memoryAreaCode = "R";  //Internal relay
	private static final String readContact = "RC";
	private static final String sendSymbol ="#";
	//private static final String monitorPoint="MG";
	private static final String registerMonitor="MD";
	private static final String writeRegister = "WD"; 
	private static final String writeContact = "WC";
	//public static String monitorData = "D00018D00019D00004D00005D00012D00013D00001D00001D00008D00009D00016D00017D00001";
	//public static String monitorData = "D00018D00019D00004D00005D00012D00013D00001D00001D00008D00009D00016D00017D00001";
	public static String monitorData = "D00004D00008D00012D00016D00018";
	
	
	//%<station>#WDD000<dt>000<dt><PLC Value>***
	public static String writeRegister(String stationName, String dt , int plcValue){
		String command = "%" + stationName + sendSymbol+writeRegister+"D000" + dt + "000" + dt + UnitConversion.readeableToPlcHex(plcValue) + "**";
	    
		return command;
	}
	 
	//%<station>#RCSR<Address>**
	public static String readContact(String stationName, String address)
	 {
	    String command = "%" + stationName + sendSymbol+readContact+unitCode+memoryAreaCode+address + "**";
	
	    return command;
	  }
	
	public static String writeContact(String stationName,String address , String data){
		String command = "%" + stationName + sendSymbol+writeContact+unitCode+memoryAreaCode+address+data+"**";
		
		return command;
	}
	
	//<<station>#MG**
	public static String monitor(String station) {
		return "<" + station + sendSymbol+monitorResult+"**";
	}

	public static String registerMonitor(String station, String dataName) {
		return "<" + station + sendSymbol+registerMonitor + dataName + "**";
	}
	
	public static String resetMonitor(String station) {
	    return "<" + station + "#MDFFFFFF**";
	}
	
}
